import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 *  Class to represent Simon's health bar
 */
public class Health  extends Actor
{
    private int hitPoints;
    private GreenfootImage[] healthBar;
    
    private retroWorld theWorld;
    
    Simon simon;
    Label label;
    
    /** Constructor - initialize Health points to 100
     * 
     */
    public Health()
    {
        
        hitPoints=100;
        healthBar = new GreenfootImage[4];
        fillHealthImages();
        label = new Label("100/100");
        
    }
    
    public void addedToWorld(World world)
    {
        theWorld = (retroWorld)world;
        simon = theWorld.getSimon();
        theWorld.addObject(label,getX()-20,getY());
    }
    
    public void act() 
    {
        changeHealthText();
    }
    
    /** Change the text representation in the Health bar
     * 
     */
    public void changeHealthText(){
        
       label.setText(hitPoints + "/100");        
    }
    
    /** Initialize Health Bar colors
     * 
     */
    public void fillHealthImages()
    {
        healthBar[3] = new GreenfootImage("healthGreen.png");
        healthBar[2] = new GreenfootImage("healthYellow.png");
        healthBar[1] = new GreenfootImage("healthRed.png");
    }
    
    /** take damage and set healthBar image appropriately
     * 
     */
    public void takeDamage(){
        if (hitPoints == 0){
            simon.dead();
            return;
        }
        
        hitPoints -= 1;
        
        if (hitPoints == 66)
            setImage(healthBar[2]);
        else if (hitPoints == 33)
            setImage(healthBar[1]);
            
        changeHealthText();
    }
    
    public void life(){
        if (hitPoints != 100){
            hitPoints+=10;
            return;
        }
    }
    
    /** return our hit points
     * 
     */
    public int getHitPoints(){
        return hitPoints;
    }
}